package codingforgreat.lchot150;

public class Lc125 {
    public boolean isPalindrome(String s) {
        char[] str = s.toCharArray();
        int L = 0;
        int R = str.length - 1;
        while(L <= R){
            if(!isVail(str[L]) || !isVail(str[R])){
                if(!isVail(str[L])){
                    L++;
                }
                if(!isVail(str[R])){
                    R--;
                }
            }else{
                if(!isEquals(str[L],str[R])){
                    return false;
                }
                L++;
                R--;
            }
        }
        return true;
    }
    public boolean isVail(char x){
        if(x >= '0' && x <= '9'){
            return true;
        }
        if((x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z')){
            return true;
        }
        return false;
    }
    public boolean isEquals(char x,char y){
        if((x >= '0' && x <= '9') && (y >= '0' && y <= '9')){
            return x == y;
        }
        if(((x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z')) && ((y >= 'a' && y <= 'z') || (y >= 'A' && y <= 'Z'))){
            return x==y || (Math.max(x,y) - Math.min(x,y) == 32);
        }
        return false;
    }
}
